import Vue from 'vue'

import Cookies from 'js-cookie'

// import 'default-passive-events'
import Element from 'element-ui'

import './styles/element-variables.scss'
import '@/styles/index.scss' // global css
import '@riophae/vue-treeselect/dist/vue-treeselect.css'

import App from './App'
import store from './store'
import router from './router'

import './permission'
import './utils/error-log'

// 顶部公共表单
import CommonForm from './components/CommonForm'
// 公共表格
import CommonTable from './components/CommonTable'
// 公共导入
import ToChannel from './components/ToChannel'
import SvgIcon from './components/SvgIcon'
// 树形下拉多选
import Treeselect from '@riophae/vue-treeselect'

import * as filters from './filters' // global filters
import { convertToKebabCase } from './utils'
import * as Common from './utils/common'
import * as Directives from './utils/directives'
import Patch from './utils/patch'
import permission from './directive/permission'
import drag from './directive/el-drag-dialog'
import copy from './directive/copy'
import download from 'downloadjs'
import HljsVuePlugin from '@highlightjs/vue-plugin'
import { i18n } from '@/i18n'

// 补丁库
Vue.use(Patch)
Vue.use(HljsVuePlugin)

// 本地化svg图标
import 'virtual:svg-icons-register'

// 全局方法注册
Vue.prototype.$download = download

// 全局组件注册
Vue.component('svg-icon', SvgIcon)
Vue.component('common-form', CommonForm)
Vue.component('common-table', CommonTable)
Vue.component('to-channel', ToChannel)
Vue.component('treeselect', Treeselect)

// 全局指令注册
Vue.directive('permission', permission)
Vue.directive('drag', drag)
Vue.directive('copy', copy)

// 工具类指令注册
Object.keys(Directives).forEach(key => {
  Vue.directive(convertToKebabCase(key), Directives[key])
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.use(Element, {
  size: Cookies.get('size') || 'mini'
  // locale: enLang // 如果使用中文，无需设置，请删除
})
// 全局方法注册
Object.keys(Common).forEach(key => {
  Vue.prototype[key] = Common[key]
})

Vue.config.productionTip = false
Vue.config.devtools = false
new Vue({
  el: '#app',
  i18n,
  router,
  store,
  render: h => h(App)
})
